<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<title>个人注册</title>


    <link rel="stylesheet" type="text/css" href="/css/webbase.css" />
    <link rel="stylesheet" type="text/css" href="/css/pages-register.css" />
</head>

<body>
	<div class="register py-container ">
		<!--head-->
		<div class="logoArea">
			<a href="" class="logo-bd"></a>
		</div>
		<!--register-->
		<div class="registerArea">
			<h3>注册新用户<span class="go">我有账号，去<a href="/login" >登陆</a></span></h3>
			<div class="info">
				<form class="sui-form form-horizontal" id="registerForm">
					<div class="control-group">
						<label class="control-label">用户名：</label>
						<div class="controls">
							<input type="text" name="username" placeholder="请输入你的用户名" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label for="password"  class="control-label">登录密码：</label>
						<div class="controls">
							<input type="password" id="password" name="password" placeholder="设置登录密码" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label for="repassword" class="control-label">确认密码：</label>
						<div class="controls">
							<input type="password" placeholder="再次确认密码" id="repassword" name="repassword" class="input-xfat input-xlarge">
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">手机号：</label>
						<div class="controls">
							<input type="text" name="phone" id="phone" placeholder="请输入你的手机号" class="input-xfat input-xlarge">
						</div>
					</div>
					<div class="control-group">
						<label for="message" class="control-label" >短信验证码：</label>
						<div class="controls">
							<input type="text"  placeholder="短信验证码" name="message" id="message" class="input-xfat input-xlarge">  <a href="#" id="sendMessage" >获取短信验证码</a>
						</div>
					</div>
					
					<div class="control-group">
						<label for="inputPassword" class="control-label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
						<div class="controls">
							<input name="m1" type="checkbox" value="2" checked=""><span>同意协议并注册《东东商城用户协议》</span>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label"></label>
						<div class="controls btn-reg">
							<a class="sui-btn btn-block btn-xlarge btn-danger" onclick="register()" >完成注册</a>
						</div>
					</div>
				</form>
				<div class="clearfix"></div>
			</div>
		</div>
		<!--foot-->
		<div class="py-container copyright">
			<ul>
				<li>关于我们</li>
				<li>联系我们</li>
				<li>联系客服</li>
				<li>商家入驻</li>
				<li>营销中心</li>
				<li>手机东东商城</li>
				<li>销售联盟</li>
				<li>东东商城社区</li>
			</ul>
			<div class="address">地址：北京市昌平区沙阳路18号 邮编：100000 电话：400-0123-302</div>
			<div class="beian">京ICP备08006666号京公网安备11010888888
			</div>
		</div>
	</div>


<script type="text/javascript" src="/js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="/js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="/js/pages/register.js"></script>
</body>

</html>
<script type="text/javascript">
	function register() {
		var pwd = $("#password").val();
		var repwd = $("#repassword").val();
		var phone = $("#phone").val();
		var message = $("#message").val();
		if(pwd != repwd){
			alert("两次密码不一致,请重新输入")
			return ;
		}
		if(phone.length != 11 ){
			alert("请输入正确的手机号")
			return ;
		}
		/*if(message.length != 6 ){
			alert("请输入正确验证码")
			return ;
		}*/

		$.ajax({
			url: "/user/register",
			type: "post",
			dataType: "json",
			async: true,
			data:$("#registerForm").serialize(),message:$("#message").val(),
			success:function (result){
				if(result.data == 1){
					alert("注册成功")
					location.href="/login";
				}else if(result.data == 2){
					alert("验证码错误")
				}else {
					alert("系统加载失败,请联系管理员")
				}
			},
			error:function (result){
				alert("加载失败,请联系管理员")
			},
		})
	}

		wait = 60;
	 function wait_time(btn) {
		 if (wait == 0) {
			   btn.removeAttribute("disabled");
				btn.innerText = "发送验证码";
			   wait = 60;
			} else {
				btn.setAttribute("disabled", true);
			   btn.innerText = wait+"秒后重新发送";
			   wait--;
			   setTimeout(function(){wait_time(btn);},1000);
			 }
	 }
	document.getElementById('sendMessage').onclick = function(){wait_time(this)};
	//发送验证码
	$("#sendMessage").click(function () {
		//获取#phoneNum的值，去发送
		var phoneNum=$("#phone").val();
		if(phoneNum.length != 11){
			alert("手机号格式不正确，请重新输入！");
		}else{
			//异步请求web服务，去发送短信
			$.ajax({
				url:"/user/sendMessage",
				data:{phone:phoneNum},
				dataType:"json",
				type:"post",
				success:function(result){
					alert("消息发送成功,请查收！");
				}
			});
		}
	});

</script>